const https = require('https')
// 是后端像后端请求
const http = require('http')
const querystring = require("querystring")
const url = require('url')
const postData = querystring.stringify({
    name: "李四",
    age: 23,
    sex: 0
})
const server = http.createServer((req, res) => {

    let urlstr = req.url;
    let urlObj =  url.parse(urlstr,true)
    console.log(urlObj.pathname);
    switch (urlObj.pathname) {
        case '/api/data':
            res.writeHead(200, {
                'content-type': "application/json;chartset=utf-8",
            })
            res.write(postData)
  
            break;

        default:
            res.write('not fond')
            break;
    }
    res.end()

})
server.listen('3000', () => {
    console.log('q');
})
